package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.SalesSettingModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.NewMainContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;

/**
 * Description:
 * Created by FHW
 * on 2017/8/16
 */

public class NewMainPresenter extends BasePresenter implements NewMainContract.Presenter {
    private NewMainContract.View view;
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    @Inject
    public NewMainPresenter(NewMainContract.View view) {
        this.view = view;
    }

    @Override
    public void getSalesSetting(String SalesID) {
        rsaJsonUtil.put("SalesID", SalesID);
        view.showLoadingDialog(mContext.getString(R.string.text_loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.getSalesSetting(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<SalesSettingModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(SalesSettingModel salesSettingModel) {
                        view.loadSucSaleSetting(salesSettingModel.getData());
                    }
                });
    }

}
